package com.shixj.easy.spider.service;

import com.shixj.easy.spider.mapper.RecordMapper;
import com.shixj.easy.spider.model.AbstractEntity;
import com.shixj.easy.spider.model.Record;
import com.shixj.ef.vo.FetchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by shixj on 2018/1/16.
 */
@Service
public class RecordServiceImpl implements RecordService {
    @Autowired
    RecordMapper recordMapper;
    /**
     * 保存记录
     *
     * @param result
     * @param abstractEntity
     */
    @Override
    public void saveRecord(FetchResult result, AbstractEntity abstractEntity) {
        Record record = new Record();
        record.setSourceId(abstractEntity.getSourceId());
        record.setSourceUrl(result.getUrl());
        record.setTime(new Date());
        recordMapper.insert(record);
    }

    @Override
    public Record buildRecord(FetchResult result, AbstractEntity abstractEntity) {
        Record record = new Record();
        record.setSourceId(abstractEntity.getSourceId());
        record.setSourceUrl(result.getUrl());
        record.setTime(new Date());
        return record;
    }

    @Override
    public void saveRecords(List<Record> records) {
          recordMapper.batchInsertRecord(records);
    }
}
